<!--
 * @Author: delin66
 * @Date: 2024-12-04 22:23:15
 * @LastEditors: delin66
 * @LastEditTime: 2024-12-14 18:33:47
 * @Descripttion: 
-->
<template>
  <div class="container">
    <el-drawer :model-value="drawerVisile" :before-close="handleClose">
      <template #header>
        <span class="title">会议室预约</span>
      </template>
      <div class="content">
        <el-form ref="formRef" label-width="auto" :model="reserveForm" label-position="top">
          <el-form-item label="预约时段:" required>
            <div class="timeRange">
              <el-date-picker
                v-model="reserveForm.startTime"
                type="datetime"
                placeholder="选择会议开始时间"
              />-<el-date-picker
                v-model="reserveForm.endTime"
                type="datetime"
                placeholder="选择会议结束时间"
              />
            </div>
          </el-form-item>
          <el-form-item label="备注:">
            <el-input v-model="reserveForm.remark" type="textarea" :rows="3" placeholder="请输入备注内容" />
          </el-form-item>
          <el-form-item>
            <div class="btn">
              <el-button type="primary" @click="handleSubmit">提交</el-button>
              <el-button @click="handleClose">取消</el-button>
            </div>
          </el-form-item>
        </el-form>
      </div>
    </el-drawer>
  </div>
</template>
<script setup lang="ts">
import { ref, reactive } from 'vue';
import { useRoomReserveStore } from '@/store/roomReserve';
import { storeToRefs } from 'pinia';
import dayjs from 'dayjs';
import { ElMessage } from 'element-plus';

const useRoomReserve = useRoomReserveStore();
const { roomReserveList, reserveForm } = storeToRefs(useRoomReserve);

const date = ref('');
const props = defineProps(['drawerVisile']);
const emits = defineEmits(['update:drawerVisile']);

const disabledDate = (time: Date) => {
  const now = new Date();
  now.setHours(0, 0, 0, 0); // 设置为今天的00:00:00（即去除时分秒部分）
  return time < now; // 禁用今天之前的日期（不包括今天）
};
/**
 * 关闭抽屉
 */
const handleClose = () => {
  emits('update:drawerVisile', false);
  console.log('close');
};
const handleSubmit = () => {
  console.log(reserveForm.value);
  if(!reserveForm.value.startTime){
    ElMessage.error('请选择开始时间')
    return
  }
  if(!reserveForm.value.endTime){
    ElMessage.error('请选择结束时间')
    return;
  }
  reserveForm.value.startTime = dayjs(reserveForm.value.startTime).format('YYYY-MM-DD HH:mm:ss');
  reserveForm.value.endTime = dayjs(reserveForm.value.endTime).format('YYYY-MM-DD HH:mm:ss');
  useRoomReserve.addRoomReserve(reserveForm.value);
  handleClose();
};
</script>
<style scoped lang="scss">
:deep(.el-drawer__header) {
  margin-bottom: 10px;
}
.title {
  font-size: 24px;
  font-weight: bold;
}
.timeRange {
  width: 100%;
  display: flex;
  justify-content: space-between;
  .time {
    width: 45%;
  }
}
.btn {
  width: 100%;
  display: flex;
  justify-content: flex-end;
}
</style>
